package com.apes.scm.account.ledger.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.plugin.soe.metadata.BusinessAttribute;
import com.apes.framework.plugin.soe.metadata.BusinessAttributeValue;
import com.apes.framework.util.LogicalUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：帐目类型分组
 *
 * @author xul
 * @create 2018-11-03 14:13
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = LedgerGroup.CONST_TABLE_NAME)
public class LedgerGroup extends BaseModel {
    public static final String CONST_TABLE_NAME = "acc_ledger_group";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "帐目类型分组")
    @Comment("帐目分组编号")
    private String id;

    @Column(name = "name", nullable = false, length = 60)
    @Comment("名称")
    private String name;

    @States(name = "合作伙伴类型", values = {
            @State(id = "supplier", name = "供应商"),
            @State(id = "customer", name = "客户"),
            @State(id = "both", name = "供应商或客户")})
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "partner_type", nullable = false, referencedColumnName = "id")
    private BusinessAttributeValue partnerType;

    @States(name = "帐目方向", values = {
            @State(id = "1", name = "正项"),
            @State(id = "-1", name = "负项")})
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "loan", nullable = false, referencedColumnName = "id")
    private BusinessAttributeValue loan;

}
